package com.hue.controller;

import com.hue.entity.R;
import com.hue.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/vod")
public class VodController {
    @Autowired
    private VodService vodService;

    @PostMapping("/upload")
    public R upload(MultipartFile file) {
        String videoId = vodService.upload(file);
        return R.ok().data("videoId", videoId);
    }

    //根据视频id删除视频
    @GetMapping("/delete/{videoId}")
    public R delete(@PathVariable("videoId") String videoId) {
        return vodService.delete(videoId) ? R.ok() : R.error();
    }

    //一次删除多个视频
    @PostMapping("/deletes")
    public R deletes(@RequestBody List<String> videoIds) {
        return vodService.deletes(videoIds) ? R.ok() : R.error();
    }

}
